/**
 * Created by 居胜 on 2016/6/14.
 */
+function () {
    //选择器
    var $ = function (id) {
        return document.querySelector(id);
    };


    var offsetTop = $(".my-table").offsetTop;
    var offsetHeight = $(".my-table").offsetHeight;
    console.log(offsetHeight)

    //事件代理
    window.addEventListener('scroll', function (event) {

        var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
        var thLine = $(".my-table > tbody").firstElementChild;

        //滚动到达table
        if(offsetTop - scrollTop <= 0){
            thLine.style.position = "fixed";
            thLine.style.top = "0px";

            //table展示结束
            if((offsetTop + parseInt(getComputedStyle($(".my-table")).height)) <= scrollTop){
                thLine.style.position = "absolute";
            }

        }else{
            thLine.style.position = "static";
        }

    }, false)
}();